package com.interview.net;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

public class MyClient2 {

	public static void main(String[] args) throws Exception {
		Socket socket = new Socket("localhost",8080);
		//向服务器发送数据
		OutputStream outputStream = socket.getOutputStream();//获取字节输出流
		PrintWriter pw = new PrintWriter(outputStream,true);//包装成打印流
		pw.println("加班学习.....");//自动刷新
		//接收服务器发送的数据
		InputStream inputStream = socket.getInputStream();//获取字节输入流
		InputStreamReader  isr = new InputStreamReader(inputStream);//转换字符流
		char cbuf[] = new char[1024];//创建临时缓冲区
		int len = isr.read(cbuf);//读取到缓冲区
		System.out.println("服务器说:"+new String(cbuf,0,len));//输出
		
		pw.close();//关闭
		socket.close();//关闭客户端
	}
}